package com.edu.exam.entity.exampaper.review;

import com.edu.exam.enums.grading.ConfigType;
import com.edu.exam.enums.assessment.generation.Scope;
import com.edu.exam.enums.examination.paper.AlgorithmType;
import com.edu.exam.enums.exampaper.review.ExamPaperCheckTaskStatus;
import com.edu.exam.enums.common.OperationType;
import com.edu.exam.enums.common.OperationResult;
import com.edu.exam.enums.grading.audit.OperationSource;
import jakarta.persistence.*;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.time.LocalDateTime;

/**
 * 试卷查重历史实体类
 *
 * <p>记录试卷查重操作的历史信息，包括操作记录、状态变更、
 * 结果查看等审计信息。支持操作追溯和统计分析。</p>
 *
 * @author 系统生成
 * @version 2.0
 * @since 2025-11-09
 */
@Entity
@Data
@EqualsAndHashCode(callSuper = false)
@EntityListeners(AuditingEntityListener.class)
public class ExamPaperCheckHistory {

    /**
     * 主键ID
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    /**
     * 试卷ID
     */
    @Column(name = "paper_id")
    private Long paperId;

    /**
     * 试卷名称
     */
    @Column(name = "paper_name", length = 200)
    private String paperName;

    /**
     * 查重记录ID
     */
    @Column(name = "check_record_id")
    private Long checkRecordId;

    /**
     * 批量任务ID
     */
    @Column(name = "batch_task_id")
    private Long batchTaskId;

    /**
     * 操作类型
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_type", nullable = false, length = 20)
    private OperationType operationType;

    /**
     * 操作子类型
     */
    @Column(name = "operation_subtype", length = 20)
    private String operationSubType;

    /**
     * 操作描述
     */
    @Column(name = "operation_description", length = 500)
    private String operationDescription;

    /**
     * 操作人ID
     */
    @Column(name = "operator_id", nullable = false)
    private Long operatorId;

    /**
     * 操作人姓名
     */
    @Column(name = "operator_name", length = 100)
    private String operatorName;

    /**
     * 操作人角色
     */
    @Column(name = "operator_role", length = 50)
    private String operatorRole;

    /**
     * 操作时间
     */
    @Column(name = "operation_time", nullable = false)
    private LocalDateTime operationTime;

    /**
     * 操作前状态
     */
    @Column(name = "before_status", length = 50)
    private String beforeStatus;

    /**
     * 操作后状态
     */
    @Column(name = "after_status", length = 50)
    private String afterStatus;

    /**
     * 操作前数据
     */
    @Column(name = "before_data", columnDefinition = "TEXT")
    private String beforeData;

    /**
     * 操作后数据
     */
    @Column(name = "after_data", columnDefinition = "TEXT")
    private String afterData;

    /**
     * 变更字段列表
     */
    @Column(name = "changed_fields", columnDefinition = "TEXT")
    private String changedFields;

    /**
     * 操作结果
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_result", length = 20)
    private OperationResult operationResult;

    /**
     * 操作时长(毫秒)
     */
    @Column(name = "operation_duration")
    private Long operationDuration;

    /**
     * 影响记录数
     */
    @Column(name = "affected_records")
    private Integer affectedRecords;

    /**
     * 相似度分数
     */
    @Column(name = "similarity_score")
    private Integer similarityScore;

    /**
     * 是否超过阈值
     */
    @Column(name = "is_threshold_exceeded")
    private Boolean isThresholdExceeded;

    /**
     * 阈值设置
     */
    @Column(name = "threshold_value")
    private Integer thresholdValue;

    /**
     * 查重配置ID
     */
    @Column(name = "check_config_id")
    private Long checkConfigId;

    /**
     * 查重配置名称
     */
    @Column(name = "check_config_name", length = 100)
    private String checkConfigName;

    /**
     * 算法版本
     */
    @Column(name = "algorithm_version", length = 50)
    private String algorithmVersion;

    /**
     * 客户端IP地址
     */
    @Column(name = "client_ip", length = 50)
    private String clientIp;

    /**
     * 用户代理信息
     */
    @Column(name = "user_agent", length = 500)
    private String userAgent;

    /**
     * 会话ID
     */
    @Column(name = "session_id", length = 100)
    private String sessionId;

    /**
     * 请求ID
     */
    @Column(name = "request_id", length = 100)
    private String requestId;

    /**
     * 操作来源
     */
    @Enumerated(EnumType.STRING)
    @Column(name = "operation_source", length = 20)
    private OperationSource operationSource;

    /**
     * 关联业务ID
     */
    @Column(name = "business_id")
    private Long businessId;

    /**
     * 关联业务类型
     */
    @Column(name = "business_type", length = 50)
    private String businessType;

    /**
     * 操作参数
     */
    @Column(name = "operation_params", columnDefinition = "TEXT")
    private String operationParams;

    /**
     * 操作详情
     */
    @Column(name = "operation_details", columnDefinition = "TEXT")
    private String operationDetails;

    /**
     * 异常信息
     */
    @Column(name = "exception_info", columnDefinition = "TEXT")
    private String exceptionInfo;

    /**
     * 错误码
     */
    @Column(name = "error_code", length = 50)
    private String errorCode;

    /**
     * 错误消息
     */
    @Column(name = "error_message", columnDefinition = "TEXT")
    private String errorMessage;

    /**
     * 系统信息
     */
    @Column(name = "system_info", columnDefinition = "TEXT")
    private String systemInfo;

    /**
     * 扩展属性
     */
    @Column(name = "extended_attributes", columnDefinition = "TEXT")
    private String extendedAttributes;

    /**
     * 备注信息
     */
    @Column(name = "remarks", length = 500)
    private String remarks;

    /**
     * 关联历史记录ID
     */
    @Column(name = "related_history_id")
    private Long relatedHistoryId;

    /**
     * 创建时间
     */
    @CreatedDate
    @Column(name = "created_time", nullable = false, updatable = false)
    private LocalDateTime createdTime;

    /**
     * 更新时间
     */
    @LastModifiedDate
    @Column(name = "updated_time", nullable = false)
    private LocalDateTime updatedTime;

    /**
     * 是否删除
     */
    @Column(name = "is_deleted", nullable = false)
    private Boolean isDeleted = false;

    /**
     * 删除时间
     */
    @Column(name = "deleted_time")
    private LocalDateTime deletedTime;

    /**
     * 删除人ID
     */
    @Column(name = "deleted_by")
    private Long deletedBy;

}